class Solution {
    public int removeElement(int[] nums, int val) {
        int length = nums.length;
        int i = 0;
        int j = length-1;
        int num = 0;
        while(i<=j){
            if(nums[i]==val) {
                int tmp = nums[i];
                nums[i] = nums[j];
                nums[j] = tmp;
                num++;
                j--;
            } else {
                i++;
            }
        }
        return length-num;
    }
}